package com.asset.salesforce.dao;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.stereotype.Repository;

import com.asset.salesforce.domain.Appointment;

@Repository
public class AppointmentDaoImpl extends BasicDaoImpl<Appointment> {
	
	public List<Appointment> getAppointmentByParentId(Integer parentId, String parentType){
		Session session = sessionFactory.getCurrentSession();
		Query query = session.createQuery("from Appointment where  parentId = :parentId and parentType = :parentType");
		query.setParameter("parentId", parentId);
		query.setParameter("parentType", parentType);
		@SuppressWarnings("unchecked")
		List<Appointment>  appointments= query.list();
		if(appointments != null && appointments.size() > 0)
		return appointments;
		else
		return new ArrayList<Appointment>();
	}
	
	@SuppressWarnings("unchecked")
	public List<Appointment> getAppointmentEventsByEmployeeId(Integer empId,Integer parentId) {
		Session session = sessionFactory.getCurrentSession();
		Query query = session.createQuery("from Appointment where  salesMan.id = :empId And parentId=:parentId");
		query.setParameter("empId", empId);
		query.setParameter("parentId", parentId);
		List<Appointment>  events = new ArrayList<Appointment>();
		events= query.list();
		return events;
		
	}
	
	@SuppressWarnings("unchecked")
	public List<Appointment> getAppointmentEventsByEmployeeIdAndDate(Integer empId) {
		Session session = sessionFactory.getCurrentSession();
		Query query = session.createQuery("from Appointment where  salesMan.id = :empId");
		query.setParameter("empId", empId);
		List<Appointment>  events = new ArrayList<Appointment>();
		events= query.list();
		return events;
		
	}
}
